package com.uniquesoft.excelreader;
import java.io.File;
import java.util.ArrayList;
import java.util.Map;
import java.util.logging.Logger;

import com.uniquesoft.common.SourceFileLoader;


public class FolderHandler {
	private final static Logger logger = Logger.getLogger(FolderHandler.class.getName());
	private ArrayList<String> filelist;
	private String rootPath;

	public FolderHandler(String path) {
		this.filelist = new ArrayList<String>();
		this.rootPath = path;
	}

	public ArrayList<String> getFileList(){
		return this.filelist;
	}
	
	public ArrayList<String> getFileList(String path) {
		File root = new File(path);
		File[] files = root.listFiles();
		for(File file:files){     
			if(file.isDirectory()){
				getFileList(file.getAbsolutePath());
				logger.info("显示"+path+"下所有子目录："+file.getAbsolutePath());
			}else{
				this.filelist.add(file.getAbsolutePath());
				logger.info("显示"+path+"下所有文件："+file.getAbsolutePath());
			}     
		}
		return this.filelist;
	}
		
	public ArrayList<Map<Integer, Map<Integer, Object>>> resolveExcelFiles() throws Exception{
		
		this.getFileList(this.rootPath);
		
		ArrayList<Map<Integer, Map<Integer, Object>>> result = new ArrayList<Map<Integer, Map<Integer, Object>>>();
		
		for (String file: this.filelist) {
			logger.info("正在解析文件："+file);
//			ReadExcelUtils excelReader = new ReadExcelUtils(file);
//			Map<Integer, Map<Integer, Object>> map = excelReader.readExcelContent();
			Map<Integer, Map<Integer, Object>> map = SourceFileLoader.loadExcelFile(file);
			result.add(map);
		}
		return result;
		
	}
}
